package LeeJS;

public class J19_callBy {
	
	/*
			
			call by value vs call by reference
			값 이동시키기 swap
			a = 3, b = 5  -- > swap(3,5) -- > a = 5, b = 3
			
	 */
	public static void main(String[] args) {
		
		int a = 3;
		int b = 5;	//기본 자료형
		
		int[] aa = { 3 };
		int[] bb = { 5 };	//참조 자료형
		
		
		System.out.println("swap 호출전     " + "a : " + a + ", b : " + b);
		
		swap(a,b);		//기본 자료형
		
		System.out.println("swap 호출후     " + "a : " + a + ", b : " + b);
		
		
		System.out.println("swap 호출전     " + "aa : " + aa[0] + ", bb : " + bb[0]);
		
		swap(aa,bb);	//참조 자료형
		
		/*
		
		System.out.println(a + ", " + aa + ", " + aa[0]);
		a = a값, aa = 주소, aa[0] = aa값
		swap(aa[0], bb[0]);
		
		*/
		
		System.out.println("swap 호출후     " + "aa : " + aa[0] + ", bb : " + bb[0]);
		
	}//main
	
	static void swap(int x, int y){
		
		//x = y; y = x; = a = 5 b = 5
		
		int tmp = x;
		x = y;
		y = tmp;
		
		System.out.println("swap 실행중     a : " + x + ", b : " + y );
		
	}

	
	static void swap(int[] x, int[] y){
		
		int tmp = x[0];
		x[0] = y[0];
		y[0] = tmp;
		
		System.out.println("swap 실행중     " + "aa : " + x[0] + ", bb : " + y[0]);
		
	}
	
}